<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="net.zdsoft.wpchat.support.util.PageUtils"%>
<%@ page import="net.zdsoft.wpchat.android.client.Constant"%>
<%@ page import="net.zdsoft.wpchat.support.action.system.OptionAction"%>
<%@ page import="java.util.List"%>
<%@ page import="net.zdsoft.wpchat.support.entity.SysOption"%>
<%@ page import="net.zdsoft.keel.util.StringUtils"%>
<%
OptionAction action = (OptionAction)PageUtils.getAction();
List<SysOption> optionList = action.getOptionList();
if(optionList == null){
    optionList = new ArrayList<SysOption>();
}
%>
<html>
<head>
<title>后台</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript" src="../../script/jquery-1.7.2.js"></script>
<script type="text/javascript" language="javascript" src="../../script/js-utils.js"></script>
<script language="javascript">
var isSubmitting = false;
window.onload=function(){
    document.getElementById("tableMainForm").style.display="none";
};
		
//用于显示底部div,用来添加系统参数
function showDiv(isAdd){
    document.getElementById("tableMainForm").style.display="block"; 
    if(!isAdd){
        document.getElementById("value").focus();
    }
}
	
//用于判断是添加还是修改
function doAddOrModifyAction() {
    document.getElementById("dataId").value == "" ? addOptions() : modifyOptions();
}
   
//用于删除操作
function submit(action,id){
	if(action == "removeOption.htm"){
	    if (!confirm("您确认要删除该系统参数么？")) {
	        return;
	    }
	}
	
	$.post("removeOption.htm",{"id":id},function(data){
	    if(isMessageReply(data)){
            refresh();
        }else{
            printReply(data);
        }
	});
}

//刷新列表操作
function refresh() {
    if (location.hash == "") {
	    location.href = "<%=request.getContextPath()%>/support/system/optionList.htm";
	}
	else { 
	    var temp = location.href;
	    location.href = temp.substring(0, temp.indexOf("#"));
	}
};

//设置需要修改的值
function setModify(index) {
    showDiv(false);
    document.getElementById("dataId").value = document.getElementById("id_"+index).value;
    document.getElementById("code").value = document.getElementById("id_"+index).value;
    document.getElementById("value").value = document.getElementById("value_"+index).value;
    document.getElementById("name").value = document.getElementById("name_"+index).value;
    document.getElementById("decp").value = document.getElementById("decp_"+index).value;
}

// 保存修改结果 
function modifyOptions(){
    if (isSubmitting == true) {
        return ;
    }		
	if(!window.confirm("确定要保存当前修改？")){
		return ;
	}			

	var id =  document.getElementById("code").value;
	var value = document.getElementById("value").value;
	var name = document.getElementById("name").value;
	var decription = document.getElementById("decp").value;

	$.post("modifyOption.htm",{"id":id,"name":name,"value":value,"description":decription},function(data){
        if(isMessageReply(data)){
            refresh();
        }else{
            printReply(data);
        }
    });       
}

// 添加系统参数
function addOptions(){    
    if(!window.confirm("确定要保存？")){
        return ;
    }           

    var value = document.getElementById("value").value;
    var name = document.getElementById("name").value;
    var decription = document.getElementById("decp").value;
    
    $.post("addOption.htm",{"name":name,"value":value,"description":decription},function(data){
      if(isMessageReply(data)){
        refresh();
      }else{
        printReply(data);
      }
    });       
}
</script>
</head>
<body>
<div id="tableMain">
    <div><input id="dataId" type="hidden" /></div>
    <div id="message"></div>
    <div id="tableMainForm"  >
        <form name="optionsInfoForm"  action="javascript:doAddOrModifyAction()" method="post">
            <table id="dataTable" border="0" align="center" cellpadding="5" cellspacing="1">
	           <tr id="trcode" style="display: none;">
	               <td width="20%" class="titleTd">编号：</td>
	               <td width="80%">
	               <input type="text" id="code" name="code" value="" size="10" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
	               </td>
	           </tr>
	           <tr>
                   <td width="20%" class="titleTd">名称：</td>
                   <td width="80%">
                   <textarea rows="2"  id="name" name="name"></textarea>
                   </td>
               </tr>
               <tr>
                   <td width="20%" class="titleTd">值：</td>
                   <td width="80%">
                   <textarea rows="2" cols="50" id="value" name="value"></textarea>
                   </td>
               </tr>
               <tr>
                   <td width="20%" class="titleTd">描述：</td>
                   <td width="80%">
                   <textarea rows="2"  id="decp" name="decp"></textarea>
                   </td>
               </tr>
           </table>
           
           <div id="buttonRight">
               <input type="submit" name="Submit" class="colorButton" value=" 保存 "/>
               <input onclick="javascript:refresh();" type="button"  class="colorButton" value="返回"/>
           </div>
       </form>
    </div>
    
	<div id="condition">
		<span style="font-weight:bold; color:#000000">系统配置添加：</span>
		<input type="button" name="Add" class="colorButton" style="line-height:19px;font-size:12px;" value="添加" onclick="javascript:showDiv(true);" onblur="clearMessages('message');" />
	</div>
	
	<table class="dataTable" border="0" align="center" cellpadding="5" cellspacing="1" style="table-layout:fixed;word-wrap:break-word;">
	    <tr class="titleTr">
	  	    <td width="20%" align="center">名称</td>
	  	    <td width="30%" align="center">值</td>
            <td width="30%" align="center">描述</td>
	  	    <td width="20%" align="center">操作</td>
	    </tr>
	    
	    <% for(SysOption sysOption : optionList){ %>
	    <tr>
	        <td><input name="name" id="name_<%= sysOption.getId()%>" type="hidden" value="<%=StringUtils.htmlFilter(sysOption.getName()) %>"/><%=StringUtils.htmlFilter(sysOption.getName()) %></td>
	        <td><input name="values" id="value_<%=sysOption.getId() %>" type="hidden"  value="<%=sysOption.getValue() %>" style="width:350px;" onfocus="this.select();"/><%=sysOption.getValue() %></td>
            <td><input name="desp" id="decp_<%= sysOption.getId()%>" type="hidden" value="<%=StringUtils.htmlFilter(sysOption.getDecription()) %>"/><%=StringUtils.htmlFilter(sysOption.getDecription()) %></td>
	        <td align="center">
	        <input name="ids" id="id_<%=sysOption.getId() %>" type="hidden" value="<%=sysOption.getId() %>" />
            <a href="#" onclick="setModify('<%=sysOption.getId()%>')">修改</a>&nbsp; |&nbsp;<a href="javascript:submit('removeOption.htm','<%=sysOption.getId()%>')">删除</a>
	        </td>
	    </tr>
        <% }%>
	</table>
</div>
</body>
</html>